﻿using OracleSchemaProvider;
using SchemaProvider;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Plugin.Tests
{
    
    
    /// <summary>
    ///这是 OracleTableCodeProviderTest 的测试类，旨在
    ///包含所有 OracleTableCodeProviderTest 单元测试
    ///</summary>
    [TestClass()]
    public class OracleViewCodeProviderTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试属性
        // 
        //编写测试时，还可使用以下属性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        public void ToPropertyNameTest()
        {
            string msg = "OracleViewCodeProvider.ToPropertyName did not return the expected value. ";

            OracleViewCodeProvider target = new OracleViewCodeProvider();

            string columnName = null;
            string actual = target.ToPropertyName(columnName);
            Assert.IsTrue(actual == CodeUtility.EmptyDataEntity, msg + "columnName = null");

            columnName = "";
            actual = target.ToPropertyName(columnName);
            Assert.IsTrue(actual == CodeUtility.EmptyDataEntity, msg + "columnName = ''");

            columnName = "COLUMN";
            actual = target.ToPropertyName(columnName);
            Assert.IsTrue(actual == "Column", msg + "columnName =" + columnName);

            columnName = "_COLUMN_NAME";
            actual = target.ToPropertyName(columnName);
            Assert.IsTrue(actual == "ColumnName", msg + "columnName =" + columnName);

            columnName = "COLUMN_NAME_";
            actual = target.ToPropertyName(columnName);
            Assert.IsTrue(actual == "ColumnName", msg + "columnName =" + columnName);

            columnName = ".COLUMN_NAME.";
            actual = target.ToPropertyName(columnName);
            Assert.IsTrue(actual == "ColumnName", msg + "columnName =" + columnName);

            columnName = "COLUMN_NAME";
            actual = target.ToPropertyName(columnName);
            Assert.IsTrue(actual == "ColumnName", msg + "columnName =" + columnName);

            columnName = "COLUMN_NAME";
            actual = target.ToPropertyName(columnName);
            Assert.IsTrue(actual == "ColumnName", msg + "columnName =" + columnName);

            TestConvertToAbbriviation(target, msg);
        }

        private void TestConvertToAbbriviation(OracleViewCodeProvider target, string msg)
        {
            string columnName = "TABLE_NAME_id_";
            string actual = target.ToPropertyName(columnName);
            Assert.IsTrue(actual == "TableNameId", msg + "columnName =" + columnName);

            columnName = "IS";
            actual = target.ToPropertyName(columnName);
            Assert.IsTrue(actual == "Is", msg + "columnName =" + columnName);

            columnName = "UPDATED_BY";
            actual = target.ToPropertyName(columnName);
            Assert.IsTrue(actual == "UpdatedBy", msg + "columnName =" + columnName);

            columnName = "IP";
            actual = target.ToPropertyName(columnName);
            Assert.IsTrue(actual == columnName, msg + "columnName =" + columnName);
        }

        /// <summary>
        /// 
        /// </summary>
        [TestMethod()]
        public void MapClassNameTest()
        {
            string msg = "OracleViewCodeProvider.MapClassName did not return the expected value. ";

            OracleViewCodeProvider target = new OracleViewCodeProvider();

            string tableName = null;
            string actual = target.MapClassName(tableName);
            Assert.IsTrue(actual == CodeUtility.EmptyDataEntity, msg + "tableName = null");

            tableName = "";
            actual = target.MapClassName(tableName);
            Assert.IsTrue(actual == CodeUtility.EmptyDataEntity, msg + "tableName = ''");

            tableName = "APPS";
            actual = target.MapClassName(tableName);
            Assert.IsTrue(actual == "Apps", msg + "tableName =" + tableName);

            tableName = "apps";
            actual = target.MapClassName(tableName);
            Assert.IsTrue(actual == "Apps", msg + "tableName =" + tableName);

            tableName = "APPS.";
            actual = target.MapClassName(tableName);
            Assert.IsTrue(actual == "Apps", msg + "tableName =" + tableName);

            tableName = ".APPS.";
            actual = target.MapClassName(tableName);
            Assert.IsTrue(actual == "Apps", msg + "tableName =" + tableName);

            tableName = "APPS.MODULE_TABLE_NAME";
            actual = target.MapClassName(tableName);
            Assert.IsTrue(actual == "ModuleTableName", msg + "tableName =" + tableName);
        }

    }
}
